package com.meida.student.app.user.handler;

import com.meida.common.base.entity.EntityMap;
import com.meida.common.base.utils.FlymeUtils;
import com.meida.common.enums.ColleconEnum;
import com.meida.common.mybatis.query.CriteriaQuery;
import com.meida.module.system.provider.service.SysColleconService;
import com.meida.module.user.client.entity.SysLink;
import com.meida.module.user.provider.handler.BaseUserInfoHandler;
import com.meida.module.user.provider.service.SysLinkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 用户个人资料扩展
 *
 * @author zyf
 */
@Component
public class StudentUserInfoHandler extends BaseUserInfoHandler {
    @Autowired
    private SysLinkService sysLinkService;

    @Autowired
    private SysColleconService sysColleconService;

    @Override
    public void complete(CriteriaQuery cq, EntityMap map) {
        super.complete(cq, map);
        //TODO 待后台对接
        //成为学霸
        map.put("link1", "");
        SysLink link1 = querySysLink(1L);
        if (FlymeUtils.isNotEmpty(link1)) {
            map.put("link1", link1.getLinkPrefix() + link1.getLinkUrl());
        }
        //创作激励计划
        map.put("link2", "");
        SysLink link2 = querySysLink(2L);
        if (FlymeUtils.isNotEmpty(link2)) {
            map.put("link2", link2.getLinkPrefix() + link2.getLinkUrl());
        }
        //成为合伙人
        map.put("link3", "");
        SysLink link3 = querySysLink(3L);
        if (FlymeUtils.isNotEmpty(link3)) {
            map.put("link3", link3.getLinkPrefix() + link3.getLinkUrl());
        }
        Long userId = map.getLong("userId");
        long scNum = sysColleconService.countCountByTargetUser(userId, ColleconEnum.SC, "");
        long dzNum = sysColleconService.countCountByTargetUser(userId, ColleconEnum.DZ, "");
        map.put("scNum", scNum);
        map.put("dzNum", dzNum);
    }

    SysLink querySysLink(Long linkId) {
        CriteriaQuery cq = new CriteriaQuery(SysLink.class);
        cq.eq("linkId", linkId);
        cq.eq("sendStatus", 1);
        SysLink sysLink = sysLinkService.getOne(cq);
        return sysLink;
    }
}
